<template>
  <!-- 推优(项目总工)业务待办 -->
  <div class="wrapper">
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <title-name title="处理" />
      <title-name title="推优信息" />
      <a-form-model :model="goodBusDTO" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
        <a-row :gutter="24">
          <a-col :md="16" :sm="16">
            <a-form-model-item label="推优理由" prop="content">
              <BaseTextarea v-model="goodBusDTO.content" placeholder="请输入" :auto-size="{ minRows: 3, maxRows: 5 }" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="附件上传">
              <upload-list :business-code="'TM05'" :upload-arrys.sync="goodBusDTO.fileInfoVOS" :is-close="false" multiple />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <title-name title="补充信息" />
      <a-form-model ref="ruleForm" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }" :rules="rules">
        <a-row :gutter="24">
          <a-col :md="24" :sm="24">
            <a-form-model-item label="修改描述" prop="describeContent">
              <BaseTextarea v-model="form.describeContent" placeholder="请输入" :auto-size="{ minRows: 3, maxRows: 5 }" :disabled="resolveInfo"/>
            </a-form-model-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="技术方案分类" prop="technicalName" class="technicalName">
              <BaseInput v-model="form.technicalName" disabled />
              <a-button type="primary" @click="selectTechnicalClassFn" style="margin-left: 10px" v-if="!resolveInfo">选择</a-button>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>
    <div class="tool-btns page-btn-right-top" >
      <a-button :loading="loading" class="ml12" type="primary" @click="submit" v-if="!resolveInfo"> 确定处理 </a-button>
      <a-button v-if="resolveInfo && !this.$route.query.businessType " class="ml12" type="primary" @click="handleClose()">关闭</a-button>
    </div>
    <SelectTechnicalClass :visible="selectTechnicalClassVisible" :projectQualityTypeId="projectQualityTypeId" @cancel="cancelSelectTechnicalClass"></SelectTechnicalClass>
    <selectApprover
      :business-id="businessId"
      :process-config="setProcessConfig"
    />
  </div>
</template>
<script>
import UploadList from '@/components/UploadList'
import SelectTechnicalClass from './selectTechnicalClass'
import { pushProgramGood } from '@/api/technical/approval'
import { finishBusinessTodo } from '@/api/commons.js'
export default {
  props: {
    projectQualityTypeId: {
      //工程类别id
      type: String,
      required: ''
    },
    goodBusDTO: {
      //推优详情数据
      type: Object,
      default: {}
    },
    resolveInfo:{
      type: Boolean,
      default: false
    }
  },
  name: 'promotionDetail',
  components: {
    UploadList,
    SelectTechnicalClass
  },
  data() {
    return {
      form: {},
      loading: false,
      rules: {
        //technicalName: [{ required: true, message: '请选择', trigger: 'change' }],
        describeContent: [{ required: true, message: '请输入', trigger: 'change' }]
      },
      selectTechnicalClassVisible: false,
       //获取流程配置值
        processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      businessId: null,
    }
  },
  watch: {
    goodBusDTO: {
      immediate: true,
      async handler(val) {
        this.processConfig = await this.$getConfigFn('technical_program_good');  
          console.log(   this.processConfig ,'   this.processConfig ')
         if(val.technicalName && this.resolveInfo){
          this.form = val;
         }
        }
    }
  },
  methods: {
    handleClose() {
      this.$multiTab.close(this.$route.fullpath)
    },
    submit() {
      this.setProcessConfig = null;
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          if(!this.form.technicalName){
            this.$message.warning('请选择技术方案分类');
            return
          }
          let parms = {
            auditStatus: 'SUBMITTED',
            constructionProgramId: this.goodBusDTO.constructionProgramId
          }
          let req = { ...parms, ...this.form }
          this.loading = true
          pushProgramGood(req).then((res) => {
            if (res.data.code != '200') {
              return
            }
            this.businessId = this.goodBusDTO.id;
            this.setProcessConfig = this.processConfig;
          })
          finishBusinessTodo({ id: this.$route.query.messageId }).then((res1) => {
            if (res1.code !== '0') {
              return
            }
          })
          this.$message.success('处理成功')
          this.loading = false
          //this.$close()
        }
      })
    },
    //选择技术分类
    selectTechnicalClassFn() {
      this.selectTechnicalClassVisible = true
    },
    cancelSelectTechnicalClass(flag, data) {
      this.selectTechnicalClassVisible = false
      if (data) {
        this.form.technicalName = data.partialInfo
        this.form.technicalId = data.id
      }
    }
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.technicalName {
  @{deep} .ant-form-item-children {
    display: flex;
    .ant-input {
      width: 300px;
    }
  }
}
</style>
